//
//  DetailNewsView.m
//  LoveLove
//
//  Created by leiyifan on 2019/5/26.
//  Copyright © 2019 wkf. All rights reserved.
//

#import "DetailNewsView.h"
#import "UIImageView+WebCache.h"//图片加载

@interface DetailNewsView()
@property (nonatomic,strong) UILabel *titleLab;
@property (nonatomic,strong) UILabel *fromLab;
//@property (nonatomic,strong) UILabel *storeName;
@property (nonatomic,strong) UILabel *timeLab;

@property (nonatomic,strong) UILabel *content;

@property (nonatomic,strong) UIImageView *image1;

@property (nonatomic,strong) UIImageView *image2;

@property (nonatomic,strong) UIImageView *image3;
@end
@implementation DetailNewsView

//-(UIScrollView *)scrollView{
//    if (!_scrollView) {
//        _scrollView = [UIScrollView new];
//    }
//    return _scrollView;
//}

-(DetailNewsSubView *)detailSubview{
    if (!_detailSubview) {
        _detailSubview = [DetailNewsSubView new];
        _detailSubview.layer.borderWidth = 0.5;
        _detailSubview.layer.borderColor = [UIColor blackColor].CGColor;
       
    }
    return _detailSubview;
}

-(UILabel *)titleLab{
    if (!_titleLab) {
        _titleLab = [UILabel new];
        _titleLab.text = @"djladjlajdl";
        _titleLab.font = [UIFont systemFontOfSize:23 weight:0.7];
        _titleLab.textColor = [UIColor blackColor];
        _titleLab.numberOfLines = 0;
    }
    return _titleLab;
}
-(UILabel *)timeLab{
    if (!_timeLab) {
        _timeLab = [UILabel new];
        _timeLab.text = @"时间";
        _timeLab.font = [UIFont systemFontOfSize:15];
        _timeLab.textColor = [UIColor colorWithHexString:@"#545454"];
        _timeLab.numberOfLines = 0;
    }
    return _timeLab;
}
-(UILabel *)content{
    if (!_content) {
        _content = [UILabel new];
        _content.text = @"时间打哈哈的快拉黑的啊还拉大锯拉大锯垃圾袋垃圾袋绿卡就对啦对啦可获得绿卡后大号地块啦滑到阿来得及阿里打呼噜的拉黑的阿里好屌拉开点好啦";
        _content.font = [UIFont systemFontOfSize:15];
        _content.textColor = [UIColor colorWithHexString:@"#545454"];
        _content.numberOfLines = 0;
    }
    return _content;
}
-(UILabel *)fromLab{
    if (!_fromLab) {
        _fromLab = [UILabel new];
        _fromLab.text = @"原创：开开看看扩";
        _fromLab.font = [UIFont systemFontOfSize:15];
        _fromLab.textColor = [UIColor colorWithHexString:@"#545454"];
        _fromLab.numberOfLines = 0;
    }
    return _fromLab;
}
//-(UILabel *)storeName{
//    if (!_storeName) {
//        _storeName = [UILabel new];
//        _storeName.text = @"商家名称";
//        _storeName.font = [UIFont systemFontOfSize:15];
//        _storeName.textColor = [UIColor colorWithHexString:@"#545454"];
//        _storeName.numberOfLines = 0;
//    }
//    return _storeName;
//}
-(UIImageView *)image1{
    if (!_image1) {
        _image1 = [UIImageView new];
        _image1.hidden = YES;
    }
    return _image1;
}
-(UIImageView *)image2{
    if (!_image2) {
        _image2 = [UIImageView new];
        _image2.hidden = YES;
    }
    return _image2;
}

-(UIImageView *)image3{
    if (!_image3) {
        _image3 = [UIImageView new];
        _image3.hidden = YES;
    }
    return _image3;
}




-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
//         [self addSubview:self.scrollView];
        [self addSubview:self.titleLab];
//         [self.scrollView addSubview:self.storeName];
         [self addSubview:self.fromLab];
         [self addSubview:self.timeLab];
        [self addSubview:self.detailSubview];
          [self addSubview:self.content];
        [self addSubview:self.image1];
         [self addSubview:self.image2];
         [self addSubview:self.image3];
    }
    return self;
}

//article = 123456;
//collect = 0;
//"comment_num" = 0;
//id = 11;
//"img_url" =         (
//                     "https://haoaihao.oss-cn-beijing.aliyuncs.com/61558937141.jpg"
//                     );
//"is_collect" = 0;
//"is_family" = 2;
//"is_follow" = 0;
//"is_like" = 0;
//"like_num" = 0;
//"new_title" = "\U7231\U56fd\U8005";
//"new_uid" = 6;
//status = "\U5ba1\U6838\U901a\U8fc7";
//time = "2019-05-27 14:05:55";
//"u_avatar" = "http://edu.flykoi.com/uploads/users/users.jpg";
//"u_info" = "<null>";
//"u_name" = 15257583563;

-(void)configDetailNewsView:(NSDictionary *)dic{
    self.titleLab.text = dic[@"new_title"];
    self.fromLab.text = [NSString stringWithFormat:@"原创  %@",dic[@"u_name"]];
     self.timeLab.text = [NSString stringWithFormat:@"%@",dic[@"time"]];

    NSString *string = @"";
    if (dic[@"article"]){
        string = dic[@"article"];
    }

    NSAttributedString *attr = [[NSAttributedString alloc]initWithString:string];
    self.content.attributedText = attr;
    self.detailSubview.storeName.text = dic[@"u_name"];
    if ([dic[@"u_info"] isEqual:[NSNull null]]) {
         self.detailSubview.storeIntro.text = @"";
    }else{
         self.detailSubview.storeIntro.text = dic[@"u_info"];
    }
  
    NSURL *ImagePath1 =[NSURL URLWithString:dic[@"u_avatar"]];
    [self.detailSubview.iconView sd_setImageWithURL:ImagePath1 placeholderImage:[UIImage imageNamed:@"default_user"]];
    if ([dic[@"is_family"] integerValue] == 2) {

        
//        //代表的是图文
//        NSArray *array = dic[@"img_url"];
//
//        self.image1.hidden = YES;
//        self.image2.hidden = YES;
//        self.image3.hidden = YES;
//
//        float totalheight = 0;
//        for (int i = 0; i <array.count; i++) {
//
//            UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:array[i]]]];
//
//            if (i== 0) {
//
//                self.image1.hidden = NO;
//                self.image1.height = self.image1.size.height*(image.size.height/image.size.width);
//                self.image1.image = image;
//
//                totalheight += self.image1.height;
//            }
//            else if (i== 1) {
//
//                self.image2.hidden = NO;
//                self.image2.height = image.size.height;
//                self.image2.image = image;
//
//                totalheight += self.image2.height;
//            }
//            else if (i== 2) {
//
//                self.image3.hidden = NO;
//                self.image3.height = image.size.height;
//                self.image3.image = image;
//
//                totalheight += self.image3.height;
//            }
//        }
//
//        self.height += totalheight;
    }
    else{


    }
}
-(void)layoutSubviews{
    [super layoutSubviews];
//    [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.mas_left);
//        make.right.equalTo(self.mas_right);
//        make.top.equalTo(self.mas_top);
//        make.bottom.equalTo(self.mas_bottom);
//    }];
    
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).with.offset(18);
         make.top.equalTo(self.mas_top).with.offset(40);
         make.right.equalTo(self.mas_right).with.offset(-18);
    }];
    
    [self.fromLab mas_makeConstraints:^(MASConstraintMaker *make) {
       make.left.equalTo(self.mas_left).with.offset(18);
        make.top.equalTo(self.titleLab.mas_bottom).with.offset(20);
    }];
//    [self.storeName mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.fromLab.mas_right).with.offset(10);
//        make.top.equalTo(self.fromLab.mas_top);
//    }];
    [self.timeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.fromLab.mas_right).with.offset(10);
        make.top.equalTo(self.fromLab.mas_top);
    }];
    
    [self.detailSubview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).with.offset(18);
        make.top.equalTo(self.timeLab.mas_bottom).with.offset(20);
        make.right.equalTo(self.mas_right).with.offset(-18);
        make.height.equalTo(@100);
    }];
    
    [self.content mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).with.offset(18);
        make.top.equalTo(self.detailSubview.mas_bottom).with.offset(30);
        make.right.equalTo(self.mas_right).with.offset(-18);
//        make.bottom.lessThanOrEqualTo(self.mas_bottom).with.offset(-20);
    }];

//    [self.image1 mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.mas_left).with.offset(18);
//        make.top.equalTo(self.content.mas_bottom).with.offset(30);
//        make.right.equalTo(self.mas_right).with.offset(-18);
//    }];
//    [self.image2 mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.mas_left).with.offset(18);
//        make.top.equalTo(self.image1.mas_bottom).with.offset(30);
//        make.right.equalTo(self.mas_right).with.offset(-18);
//    }];
//
//    [self.image3 mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.mas_left).with.offset(18);
//        make.top.equalTo(self.image2.mas_bottom).with.offset(30);
//        make.right.equalTo(self.mas_right).with.offset(-18);
//    }];
}

@end
